<template>
  <div class="Safetycommittee-content">
    <a-card style="width: 100%">
      <div class="juanwei" v-if="company">
        <div class="title">院安委会</div>
        <div class="body-box">
          <div class="big-box">
            <a-form :form="form" :label-col="{ span: 5 }" :wrapper-col="{ span: 12 }" @submit="handleSubmit">
              <a-form-item label="主任">
                <j-select-multi-user
                  v-model="form.zr"
                  :query-config="selectUserQueryConfig"
                  @select="selectData5"
                  :disabled="disawhzr"
                />
              </a-form-item>
              <a-form-item label="副主任">
                <j-select-multi-user
                  v-model="form.fzr"
                  :query-config="selectUserQueryConfig"
                  @select="selectData2"
                  :disabled="disawhzr"
                />
              </a-form-item>
              <a-form-item label="安委会成员">
                <j-select-multi-user
                  v-model="form.awhcy"
                  :query-config="selectUserQueryConfig"
                  @select="selectData3"
                  :disabled="disawhzr"
                />
              </a-form-item>
              <a-form-item :wrapper-col="{ span: 12, offset: 5 }">
                <a-button type="primary" html-type="submit" :disabled="disawhzr"> 确定 </a-button>
                <a-tooltip>
                  <template slot="title"> 编辑后将全部重新选择 </template>
                  <a-button type="primary" @click="editclick" style="margin-left: 20px"> 编辑 </a-button>
                </a-tooltip>
              </a-form-item>
            </a-form>
          </div>
        </div>
      </div>
      <div class="juanwei" v-else>
        <div class="title">局安委会</div>
        <div class="body-box">
          <div class="big-box">
            <a-form :form="form" :label-col="{ span: 5 }" :wrapper-col="{ span: 12 }" @submit="handleSubmit">
              <a-form-item label="安委会主任">
                <j-select-multi-user
                  v-model="form.awhzr"
                  :query-config="selectUserQueryConfig"
                  @select="selectData"
                  :disabled="disawhzr"
                />
              </a-form-item>
              <a-form-item label="常务副主任">
                <j-select-multi-user
                  v-model="form.cwfzr"
                  :query-config="selectUserQueryConfig"
                  @select="selectData1"
                  :disabled="disawhzr"
                />
              </a-form-item>
              <a-form-item label="副主任">
                <j-select-multi-user
                  v-model="form.fzr"
                  :query-config="selectUserQueryConfig"
                  @select="selectData2"
                  :disabled="disawhzr"
                />
              </a-form-item>
              <a-form-item label="安委会成员">
                <j-select-multi-user
                  v-model="form.awhcy"
                  :query-config="selectUserQueryConfig"
                  @select="selectData3"
                  :disabled="disawhzr"
                />
              </a-form-item>
              <a-form-item label="安委会办公室主任">
                <j-select-multi-user
                  v-model="form.awhbgszr"
                  :query-config="selectUserQueryConfig"
                  @select="selectData4"
                  :disabled="disawhzr"
                />
              </a-form-item>
              <a-form-item :wrapper-col="{ span: 12, offset: 5 }">
                <a-button type="primary" html-type="submit" :disabled="disawhzr"> 确定 </a-button>
                <a-tooltip>
                  <template slot="title"> 编辑后将全部重新选择 </template>
                  <a-button type="primary" @click="editclick" style="margin-left: 20px"> 编辑 </a-button>
                </a-tooltip>
              </a-form-item>
            </a-form>
          </div>
        </div>
      </div>
    </a-card>
  </div>
</template>
<script>
import { mapState } from 'vuex'
import { addSafeOrg, getSafeOrg } from '@api/manage'
import JSelectUserByDep from '@/components/jeecgbiz/JSelectUserByDep' // 部门多选
import JSelectMultiUser from '@/components/jeecgbiz/JSelectMultiUser1' // 用户多选组件
import TransferBarVue from '../../components/chart/TransferBar.vue'
export default {
  name: 'Safetycommittee',
  components: { JSelectUserByDep, JSelectMultiUser },
  data() {
    return {
      jushow: true,
      form: {
      },
      query: {
        awhzr: [], // 安委会主任
        cwfzr: [], // 副主任
        fzr: [], // 常务副主任
        awhcy: [], // 安委会成员
        awhbgszr: [], // 安委会办公室主任
        zr: [], // 常务副主任
        company: '',
      },

      users: '',
      // 选择用户查询条件配置
      selectUserQueryConfig: [{ key: 'realname', label: '姓名' }],
      url: 'business/safeOrg/add',
      geturl: 'business/safeOrg/listSafeOrg',
      disawhzr: false,
    }
  },
  created() {
    this.getlistSafeOrg() // 获取安委会成员列表
    this.query.company = this.company
  },
  mounted() {},
  computed: {
    ...mapState({
      company: (state) => state.user.company,
    }),
  },
  methods: {
    // 获取安委会成员
    getlistSafeOrg() {
      getSafeOrg(this.geturl, { company: this.company }).then((res) => {
       
        if (res.code === 200) {
          this.form = res.result
          let objleg =  Object.keys(res.result)
           console.log('获取安委会成员列表', objleg)
          this.disawhzr = objleg.length==0 ? false : true
        }
      })
    },
    editclick() {
      this.form = {}
      this.disawhzr = false
    },
    selectData(rows) {
      console.log('当前改变的值', rows)
      this.query.awhzr = rows.map((item) => {
        return {
          userId: item.id,
          userName: item.realname,
          telphone: item.phone,
          // company: this.company,
          postType: 'awhzr',
        }
      })
    },
    selectData1(rows) {
      this.query.cwfzr = rows.map((item) => {
        return {
          userId: item.id,
          userName: item.realname,
          telphone: item.phone,
          // company: this.company,
          postType: 'cwfzr',
        }
      })
    },
    selectData2(rows) {
      this.query.fzr = rows.map((item) => {
        return {
          userId: item.id,
          userName: item.realname,
          telphone: item.phone,
          // company: this.company,
          postType: 'fzr',
        }
      })
    },
    selectData3(rows) {
      this.query.awhcy = rows.map((item) => {
        return {
          userId: item.id,
          userName: item.realname,
          telphone: item.phone,
          // company: this.company,
          postType: 'awhcy',
        }
      })
    },
    selectData4(rows) {
      this.query.awhbgszr = rows.map((item) => {
        return {
          userId: item.id,
          userName: item.realname,
          telphone: item.phone,
          // company: this.company,
          postType: 'awhbgszr',
        }
      })
    },
    selectData5(rows) {
      this.query.zr = rows.map((item) => {
        return {
          userId: item.id,
          userName: item.realname,
          telphone: item.phone,
          // company: this.company,
          postType: 'zr',
        }
      })
    },
    // 确定按钮
    handleSubmit(e) {
      e.preventDefault()
      console.log('this.query', this.query)
      addSafeOrg(this.url, this.query).then((res) => {
        if (res.code === 200) {
          this.$message.success(res.message)
          this.disawhzr = true
        }
      })
    },
  },
}
</script>
<style scoped lang="less">
.Safetycommittee-content {
  .juanwei {
    margin-left: 30px;
    margin-top: 30px;
    .title {
      font-size: 20px;
    }
    .body-box {
      margin: 20px 40px;
      .big-box {
        margin: 20px 0;
        height: 40px;
        line-height: 30px;
        // background-color: #f0f;
        .span-box {
          display: inline-block;
          width: 130px;
          text-align: right;
          margin-right: 10px;
        }
        .select-box {
          display: inline-block;
          width: 500px;
        }
      }
    }
  }
}
</style>